<template>
	<view class="detail-view">
		<view class="top-bar"><uni-navbar :fixed="true" :back="true" color="#fff" title="内容详情"></uni-navbar></view>

		<view class="detail-info" v-if="sqmyInfo.id">
			<view class="info-title">
				<view class="title-top">{{ sqmyInfo.title }}</view>
				<view class="title-btm">
					<text class="btm-name">{{ sysUser ? sysUser.userName : '' }}</text>
					<text class="btm-time">{{ sqmyInfo.createTime | parseTime('{y}-{m}-{d}') }}</text>
				</view>
			</view>
			<view class="info-detail">
				<view class="info-h2">正文内容</view>
				<view class="overflow"><uni-parse :content="sqmyInfo.content"></uni-parse></view>
			</view>
		</view>

		<view class="uploader-add" @click="onTts">
			<image v-if="!play" src="/static/img/icon_76.png" mode="widthFix"></image>
			<image src="/static/img/icon_77.gif" v-else mode="widthFix"></image>
		</view>

		<view class="file-list" v-if="fileList.length > 0">
			<view>附件:</view>
			<view class="file-item" v-for="(item, index) in fileList" :key="index" @click="$showLine(item)">
				<view class="file-name clamp">{{ item.name }}</view>
				<view class="right-type">预览</view>
			</view>
		</view>
		<view class="fiexd-btm" v-if="status == 0">
			<text>此民意选择您为联名人</text>
			<view class="flex-box">
				<u-button class="form-btn" type="error" @click="jointlyersSign(1)">同意</u-button>
				<u-button @click="jointlyersSign(2)">拒绝</u-button>
			</view>
		</view>
		<view class="form-box form-box-show" v-if="sqmyInfo.id">
			<u-form ref="uForm">
				<u-form-item class="form-item" label="签发">{{ sqmyInfo.edit }}</u-form-item>
				<u-form-item class="form-item" label="编辑">{{ sqmyInfo.issue }}</u-form-item>
				<!-- <u-form-item class="form-item" label="审核结果">{{ sqmyInfo.adoption ? sqmyInfo.adoption : '' }}</u-form-item> -->
				<u-form-item class="form-item" label="信息类别">{{ typeList[sqmyInfo.type] }}</u-form-item>
				<u-form-item class="form-item" label="提交时间">{{ sqmyInfo.createTime | parseTime('{y}-{m}-{d}') }}</u-form-item>
			</u-form>
		</view>
	</view>
</template>

<script>
import uniParse from '@/components/uni-parse/parse.vue';
import { mapState } from 'vuex';
export default {
	components: {
		uniParse
	},
	data() {
		return {
			statusMap: {
				0: '所有',
				1: '待审核',
				2: '待报送',
				3: '待批示',
				4: '已存档',
				5: '不采纳',
				6: '退回',
				7: '暂存',
				8: '撤回'
			},
			typeList: {},
			id: '',
			status: '1',
			sqmyInfo: {},
			fileList: [],
			sysUser: {},
			play: false
		};
	},
	onLoad(option) {
		this.loadLogin();
		this.id = option.id;
		if (option.status) {
			this.status = option.status;
		}
		this.loadDict('sqmy_category', 'typeList');
		this.loadData();
	},
	onHide() {
		this.$ttsOff();
	},
	onUnload() {
		this.$ttsOff();
	},
	computed: {
		...mapState(['userInfo'])
	},
	methods: {
		loadLogin() {
			if (this.userInfo.Authorization) {
				this.clientCode = this.userInfo.sysUser.clientCode;
				this.userId = this.userInfo.sysUser.id;
			} else {
				this.$logout();
			}
		},
		jointlyersSign(state) {
			this.$request('/sheqingminyi/sqmy-joint-celebrities/agreeOrReject', {
				sqmyJointCelebrities: {
					jointCelebritiesId: this.userId,
					sqmyId: this.id,
					status: state
				}
			}).then((res) => {
				this.$msg('操作成功');
				this.status = state;
				let pre = this.$prePage();
				if (pre && pre.loadData) {
					pre.loadData('refresh');
				}
			});
		},
		loadDict(type, list) {
			this.$request('/system/sys-dict/dictList', {
				clientCode: this.clientCode,
				sysDict: {
					dictType: type
				}
			}).then((res) => {
				if (!res.data) {
					return false;
				}
				res.data.forEach((item) => {
					this[list][item.dictValue] = item.dictName;
				});
			});
		},
		loadData() {
			this.$request('/sheqingminyi/sqmy/detail', {
				id: this.id,
				userId: this.userId
			}).then((res) => {
				this.fileList = res.data.fileList;
				this.sqmyInfo = res.data.sqmy;
				this.sysUser = res.data.sysUser;
			});
		},
		downLoad(item) {
			const downloadTask = uni.downloadFile({
				url: config.def().baseUrl + 'file/download/' + item.id,
				success: (res) => {
					if (res.statusCode == 200) {
					}
					uni.saveFile({
						tempFilePath: res.tempFilePath,
						success: function (red) {}
					});
				}
			});

			downloadTask.onProgressUpdate((res) => {});
		},
		onTts() {
			let text = this.sqmyInfo.title;
			text += this.sysUser ? this.sysUser.userName : '';
			text += ',' + this.$parseTime(this.sqmyInfo.createTime, '{y}-{m}-{d}');
			text += ',' + this.$htmlRegx(this.sqmyInfo.content);
			this.$tts(text, this, 500);
		},
		previewImage(idx, images) {
			uni.previewImage({
				current: idx,
				urls: images
			});
		}
	}
};
</script>

<style lang="scss">
.detail-view {
	background-color: #fff;
}

.form-box {
	border-top: 10rpx solid $u-border-color;

	.form-item {
		@include mp-flex;
	}
}

.fiexd-btm {
	position: static;
	border-top: 10rpx solid $u-border-color;
	padding: 30rpx;
	font-size: 16px;
	line-height: 48px;

	display: flex;
	align-items: center;
	justify-content: space-between;
}
</style>
